package aitrade.manual;

import java.io.IOException;

import com.tokenmaster.aitrade.common.account.Account;
import com.tokenmaster.aitrade.common.ticker.Ticker_Spot;
import com.tokenmaster.aitrade.market.okex.Market_Okex_Spot;

/**
 * Hello world!
 *
 */
public class App {
	/**
	 * 现价买入，参数买入数量
	 * 
	 * @param args
	 */
	public static void main(String[] args) {

		if (args[0].isEmpty() || args[0].equals("")) {
			System.out.println("require trade type");
			return;
		}

		String tradeType = args[0];

		if (args[1].isEmpty() || args[1].equals("")) {
			System.out.println("require trade cost");
			return;
		}

		double cost = Double.valueOf(args[1]);

		// 获取当前价格

		try {
			Market_Okex_Spot market_Okex_Spot = Market_Okex_Spot.getInstance();
			Ticker_Spot ticker_Spot = market_Okex_Spot.getTicker_Spot("btc_usdt");
			double price = Double.valueOf(ticker_Spot.getLast());

			Account account = new Account("小布", "1", "BTC");
			account.setUnixtime(Long.valueOf(ticker_Spot.getDate()) * 1000);

			if (tradeType.equals("buy")) {
				account.buyCoinByMoney(price, cost, Long.valueOf(ticker_Spot.getDate()) * 1000);
				System.out.println("现价买入");
			} else if (tradeType.equals("sell")) {
				account.sellAllCoin(price, Long.valueOf(ticker_Spot.getDate()) * 1000);
				System.out.println("现价卖出");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
